import * as vscode from 'vscode';
import {luaAiapi,apiType} from "./data/luaai";

class LuaAiCompletion implements vscode.CompletionItemProvider{
	provideCompletionItems(
		document: vscode.TextDocument, 
		position: vscode.Position, 
		token: vscode.CancellationToken, 
		context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem>> {
			//读取当前的内容
			const linePrefix = document.lineAt(position).text.substr(0, position.character).replace(".","") as keyof apiType ;
			const apiList = Object.keys(luaAiapi);
			let tips: vscode.CompletionItem[]  = [
				
			];
			if(apiList.indexOf(linePrefix) > -1){
				luaAiapi[linePrefix].forEach(e => {
					tips.push(new vscode.CompletionItem(e,vscode.CompletionItemKind.Method))
				});
			}
			return tips;
	}

}
export function activate(context: vscode.ExtensionContext) {

	console.log('Congratulations, your extension "helloworld" is now active!');

	let disposable = vscode.commands.registerCommand('helloworld.helloWorld', () => {
		vscode.window.showInformationMessage('Hello World Vs Code I am DiyCode');
	});

	context.subscriptions.push(disposable);

	context.subscriptions.push(
		vscode.languages.registerCompletionItemProvider(
			"lua",
			new LuaAiCompletion(),
			".",
		)
	)
}

// this method is called when your extension is deactivated
export function deactivate() {}
